<?php
/**
 * Created by PhpStorm.
 * User: ls721
 * Date: 2016/11/14 0014
 * Time: 23:09
 */
require(dirname(dirname(__FILE__)) . '/Domain/' . 'PushToList.php');;
require('MQTT/config.php');
require('MQTT/php_sam.php');

ini_set('default_socket_timeout', -1);
//redis
$redis = new Redis();
$redis->pconnect('127.0.0.1', 6379);

//mqtt
//create a new connection object


//apns



$push = new Domain_PushToList();

while (True) {
    try{
    $result = $redis->BRPOP('tess', 0);
    $d = json_decode($result[1], true);
        $conn = new SAMConnection();
//start initialise the connection
        $conn->connect(SAM_MQTT, array('SAM_HOST' => MQTT_SERVER_HOST, 'SAM_PORT' => MQTT_SERVER_POST));
        $msgCpu = new SAMMessage($d["content"]);
        foreach( $d['doctor_android'] as $value ){
            $conn->send('topic://' .'Doctor/'.$value, $msgCpu);
        }
        $conn->disconnect();
        $r=$push->pushMessageToListIos($d['doctor_ios'], $d['title'], $d['content']);
        print_r($r);

    print_r($d);
    }catch(Exception $e){
        print_r($e);
    }
}